<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\User;
use think\Db;
use think\Hook;

/**
 * CPS接口
 */
class Cps extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * B站检测地址
     *
     * @param string $email 邮箱
     * @param string $event 事件名称
     */
    public function saveBiliFeedback()
    {
//        file_put_contents("123get.txt",var_export($_GET, true),FILE_APPEND);
//        file_put_contents("123post.txt",var_export($_POST, true),FILE_APPEND);

        $data = [];

        $data['trackid'] = isset($_GET['trackid'])?$_GET['trackid']:null;
        $data['account_id'] = isset($_GET['account_id'])?$_GET['account_id']:null;
        $data['crid'] = isset($_GET['crid'])?$_GET['crid']:null;
        $data['os'] = isset($_GET['os'])?$_GET['os']:null;
        $data['model'] = isset($_GET['model'])?$_GET['model']:null;
        $data['mac'] = isset($_GET['mac'])?$_GET['mac']:null;
        $data['idfa'] = isset($_GET['idfa'])?$_GET['idfa']:null;
        $data['ip'] = isset($_GET['ip'])?$_GET['ip']:null;
        $data['ua'] = isset($_GET['ua'])?$_GET['ua']:null;
        $data['click_ts'] = isset($_GET['click_ts'])?$_GET['click_ts']:null;
        $data['share_code'] = isset($_GET['share_code'])?$_GET['share_code']:null;
        $data['create_time'] = date('Y-m-d H:i:s');
        $data['create_year'] = date('Y');
        $data['create_month'] = date('m');
        $data['create_day'] = date('Y-m-d');

        DB::name("cpa_bili")->insert($data);
    }

    /**
     * 腾讯检测地址
     *
     * @param string $email 邮箱
     * @param string $event 事件名称
     */
    public function saveTencentFeedback()
    {
//        file_put_contents("234get.txt",var_export($_GET, true),FILE_APPEND);
//        file_put_contents("234post.txt",var_export($_POST, true),FILE_APPEND);


        if (!empty($_GET)) {
            $params = $_GET;
        }else if(!empty($_POST)){
            $params = $_POST;
        }else {
            $params = [];
        }


        if(!empty($params)){
            $data = [];
            $data['click_id'] = isset($params['click_id'])?$params['click_id']:null;
            $data['click_time'] = isset($params['click_time'])?$params['click_time']:null;
            $data['wechat_openid'] = isset($params['wechat_openid'])?$params['wechat_openid']:null;
            $data['adgroup_id'] = isset($params['adgroup_id'])?$params['adgroup_id']:null;
            $data['ad_platform_type'] = isset($params['ad_platform_type'])?$params['ad_platform_type']:null;
            $data['ad_type'] = isset($params['ad_type'])?$params['ad_type']:null;
            $data['account_id'] = isset($params['account_id'])?$params['account_id']:null;
            $data['agency_id'] = isset($params['agency_id'])?$params['agency_id']:null;
            $data['click_sku_id'] = isset($params['click_sku_id'])?$params['click_sku_id']:null;
            $data['billing_event'] = isset($params['billing_event'])?$params['billing_event']:null;
            $data['deeplink_url'] = isset($params['deeplink_url'])?$params['deeplink_url']:null;
            $data['universal_link'] = isset($params['universal_link'])?$params['universal_link']:null;
            $data['page_url'] = isset($params['page_url'])?$params['page_url']:null;
            $data['device_os_type'] = isset($params['device_os_type'])?$params['device_os_type']:null;
            $data['process_time'] = isset($params['process_time'])?$params['process_time']:null;
            $data['promoted_object_id'] = isset($params['promoted_object_id'])?$params['promoted_object_id']:null;
            $data['promoted_object_type'] = isset($params['promoted_object_type'])?$params['promoted_object_type']:null;
            $data['real_cost'] = isset($params['real_cost'])?$params['real_cost']:null;
            $data['request_id'] = isset($params['request_id'])?$params['request_id']:null;
            $data['impression_id'] = isset($params['impression_id'])?$params['impression_id']:null;
            $data['site_set'] = isset($params['site_set'])?$params['site_set']:null;
            $data['muid'] = isset($params['muid'])?$params['muid']:null;
            $data['hash_android_id'] = isset($params['hash_android_id'])?$params['hash_android_id']:null;
            $data['hash_mac'] = isset($params['hash_mac'])?$params['hash_mac']:null;
            $data['ip'] = isset($params['ip'])?$params['ip']:null;
            $data['user_agent'] = isset($params['user_agent'])?$params['user_agent']:null;
            $data['oaid'] = isset($params['oaid'])?$params['oaid']:null;
            $data['callback'] = isset($params['callback'])?$params['callback']:null;
            $data['encrypted_position_id'] = isset($params['encrypted_position_id'])?$params['encrypted_position_id']:null;
            $data['ipv6'] = isset($params['ipv6'])?$params['ipv6']:null;
            $data['hash_oaid'] = isset($params['hash_oaid'])?$params['hash_oaid']:null;
            $data['create_time'] = date('Y-m-d H:i:s');
            $data['create_year'] = date('Y');
            $data['create_month'] = date('m');
            $data['create_day'] = date('Y-m-d');

            DB::name("cpa_teng_xun")->insert($data);
        }


    }

    /**
     * 抖音监测地址
     * @return void
     */
    public function saveDouYinFeedback()
    {
//        file_put_contents("dou_yin_get.txt",var_export($_GET, true),FILE_APPEND);
//        file_put_contents("dou_yin_post.txt",var_export($_POST, true),FILE_APPEND);

        if (!empty($_GET)) {
            $params = $_GET;
        }else if(!empty($_POST)){
            $params = $_POST;
        }else {
            $params = [];
        }

        if(!empty($params)){
            $data = [];
            $data['ts'] = isset($params['ts'])?$params['ts']:null;
            $data['os'] = isset($params['os'])?$params['os']:null;
            $data['ua'] = isset($params['ua'])?$params['ua']:null;
            $data['ip'] = isset($params['ip'])?$params['ip']:null;
            $data['model'] = isset($params['model'])?$params['model']:null;
            $data['demand_id'] = isset($params['demand_id'])?$params['demand_id']:null;
            $data['item_id'] = isset($params['item_id'])?$params['item_id']:null;
            $data['callback_param'] = isset($params['callback_param'])?$params['callback_param']:null;
            $data['callback_url'] = isset($params['callback_url'])?$params['callback_url']:null;
            $data['create_time'] = date('Y-m-d H:i:s');
            $data['create_year'] = date('Y');
            $data['create_month'] = date('m');
            $data['create_day'] = date('Y-m-d');

            DB::name("cpa_dou_yin")->insert($data);
        }
    }
}
